<template>
  <!-- 注册 -->
  <el-dialog :model-value="modelValue" title="注册" width="500" :before-close="handleClose">
    <!--内容 -->
    <el-form :rules="rules" label-position="left" label-width="auto" :model="formLabelAlign" style="max-width: 600px">
      <el-form-item label="姓名" >
        <el-input v-model="formLabelAlign.name" />
      </el-form-item>
      <el-form-item label="性别">
        <el-segmented v-model="formLabelAlign.sex" :options="locationOptions" />
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="formLabelAlign.age" />
      </el-form-item>
      <el-form-item label="手机号(账户)">
        <el-input v-model="formLabelAlign.tel" prop="tel"/>
      </el-form-item>
      <el-form-item  label="密码"  prop="password">
        <el-input type="password" v-model="formLabelAlign.password" />
      </el-form-item>
    </el-form>
    <!-- 底部 -->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="clickRegister">
          确定注册
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive } from 'vue'
import { $_register  } from "@/apis/user";
const formLabelAlign = reactive({
  name: '',
  sex: '男',
  age: '',
  tel:'',
  password:''
})
const locationOptions = ['男', '女']
const rules = reactive({
  tel: [
    { required: true, message: '请输入手机号', trigger: 'blur' },
  ],
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'change',
    },
    { min: 8, max: 16, message: '请输入正确的密码', trigger: 'blur' },
  ],
})



const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true,
    default: false
  },

})
const emit = defineEmits(['update:modelValue'])


/* 点击取消或者关闭当前弹窗触发事件 */
const handleClose = () => {
  emit('update:modelValue', false)
}

// 点击注册
const clickRegister = () => {
  $_register(formLabelAlign).then(res=>{
    console.log(res);
  })
}

</script>

<style lang="scss" scoped></style>